package DAO;

import java.awt.event.*;
import java.security.interfaces.RSAKey;

import javax.lang.model.type.NullType;
import javax.swing.*;
import java.sql.*;

import Main.DBMain;

public class ShowAll extends JFrame {
	JPanel contentPane = new JPanel();
	static JTextArea showArea = new JTextArea(100, 100);
	String course;

	public ShowAll() {
		setTitle("科目成绩");
		setSize(600, 400);
		setLocationRelativeTo(null);
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(showArea);
		showArea.setBounds(5, 5, 585, 350);
		showArea.setText("");
		setVisible(true);
		queryAll();// 查询
	}

	public void queryAll() {
		Connection conn = null;
		try {
			conn = DBMain.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		PreparedStatement pstmt;
		String sql = "select * from stu_info";// 查询语句

		try {
			pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery(sql);// 查询到对象
			ResultSetMetaData colName = rs.getMetaData();// 获取所有列名
			// 设置表头
			for (int i = 1; i < colName.getColumnCount(); i++) {
				showArea.append(colName.getColumnName(i) + "\t");
			}
			showArea.append("\n");
			while (rs.next()) {
				for (int i = 1; i < colName.getColumnCount(); i++) {
					showArea.append(rs.getString(i) + "\t");
				}
				showArea.append("\n");
			}
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
}
